const axios = require('axios')

// 测试快递代取API
async function testExpressPickupAPI() {
  try {
    console.log('开始测试快递代取API...\n')

    // 1. 测试创建订单
    console.log('1. 测试创建快递代取订单...')
    const orderData = {
      deliveryAddress: '3号宿舍楼 301室',
      deliveryTime: '今日,立即送出',
      itemSize: '小(美瞳/手机壳)左右',
      pickupCode: '123456',
      pickupLocation: '西院篮球场(第三食堂)',
      baseFee: 2.00,
      deliveryFee: 3.00,
      tipAmount: 1.00,
      selectedCoupon: '满10减2',
      riderGender: '不限性别',
      moreRequirements: false,
      userId: 'user123',
      userName: '张三',
      userPhone: '138****8888'
    }

    const createResponse = await axios.post('http://47.86.15.86:3000/express-pickup/create', orderData)
    console.log('创建订单响应:', JSON.stringify(createResponse.data, null, 2))

    if (createResponse.data.success) {
      const orderId = createResponse.data.data.orderId
      console.log(`✅ 订单创建成功，订单ID: ${orderId}\n`)

      // 2. 测试获取订单详情
      console.log('2. 测试获取订单详情...')
      const detailResponse = await axios.get(`http://47.86.15.86:3000/express-pickup/detail/${orderId}`)
      console.log('获取订单详情响应:', JSON.stringify(detailResponse.data, null, 2))
      console.log('✅ 获取订单详情成功\n')

      // 3. 测试获取用户订单列表
      console.log('3. 测试获取用户订单列表...')
      const listResponse = await axios.get(`http://47.86.15.86:3000/express-pickup/user/user123`)
      console.log('获取订单列表响应:', JSON.stringify(listResponse.data, null, 2))
      console.log('✅ 获取订单列表成功\n')

    } else {
      console.log('❌ 订单创建失败:', createResponse.data.message)
    }

  } catch (error) {
    console.error('❌ 测试失败:', error.message)
    if (error.response) {
      console.error('响应数据:', error.response.data)
    }
  }
}

// 测试地址API
async function testAddressAPI() {
  try {
    console.log('\n开始测试地址API...\n')

    // 1. 测试获取地址列表
    console.log('1. 测试获取地址列表...')
    const listResponse = await axios.get('http://47.86.15.86:3000/address/list?userId=user123')
    console.log('获取地址列表响应:', JSON.stringify(listResponse.data, null, 2))
    console.log('✅ 获取地址列表成功\n')

  } catch (error) {
    console.error('❌ 地址API测试失败:', error.message)
    if (error.response) {
      console.error('响应数据:', error.response.data)
    }
  }
}

// 运行测试
async function runTests() {
  await testAddressAPI()
  await testExpressPickupAPI()
  console.log('\n🎉 所有测试完成！')
}

runTests()

